package com.context;

import com.beans.factory.BeanDefinition;
import com.beans.factory.BeanDefinitionRegistry;
import com.beans.factory.ConfigurableListableBeanFactory;
import com.beans.factory.DefaultListableBeanFactory;
import com.core.io.Resource;
import com.core.io.ResourceLoader;
import com.core.io.ResourcePatternResolver;

import java.io.IOException;

public class GenericApplicationContext extends AbstractApplicationContext implements BeanDefinitionRegistry {

    private final DefaultListableBeanFactory beanFactory;

    private ResourceLoader resourceLoader;

    public GenericApplicationContext() {
        this.beanFactory = new DefaultListableBeanFactory();
    }

    @Override
    public Resource[] getResources(String locationPattern) throws IOException {
        if (this.resourceLoader instanceof ResourcePatternResolver) {
            return ((ResourcePatternResolver) this.resourceLoader).getResources(locationPattern);
        }
        return super.getResources(locationPattern);
    }

    @Override
    protected void refreshBeanFactory() {

    }

    @Override
    public ConfigurableListableBeanFactory getBeanFactory() {
        return null;
    }

    @Override
    public Object getBean(String name) throws Exception {
        return null;
    }

    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        this.beanFactory.registerBeanDefinition(beanName, beanDefinition);
    }

    @Override
    public void removeBeanDefinition(String beanName) throws Exception {

    }

    @Override
    public BeanDefinition getBeanDefinition(String beanName) throws Exception {
        return null;
    }

    @Override
    public boolean containsBeanDefinition(String beanName) {
        return false;
    }

    @Override
    public String[] getBeanDefinitionNames() {
        return new String[0];
    }

    @Override
    public int getBeanDefinitionCount() {
        return 0;
    }

    @Override
    public boolean isBeanNameInUse(String beanName) {
        return false;
    }
}
